home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / pjp / osistrea.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-02  |  645 b   |  31 lines

  1. ------------- Listing 8: The file osistrea.c -----------------
  2.  
  3. // osistream -- ostream::operator<<(streambuf&) 
  4. #include <ostream> 
  5.  
  6. ostream& ostream::operator<<(streambuf& sb) 
  7.     {    // insert from streambuf 
  8.     _Bool copied = 0; 
  9.     _TRY_IO_BEGIN 
  10.     if (opfx()) 
  11.         {    // copy characters until failure 
  12.         char buf[512]; 
  13.         int n; 
  14.         for (; 0 < (n = sb.sgetn(buf, sizeof (buf))); 
  15.             copied = 1) 
  16.             _TRY_BEGIN 
  17.                 if (rdbuf()->sputn(buf, n) != n) 
  18.                     break; 
  19.             _CATCH_ALL 
  20.                 setstate(failbit); 
  21.                 _RERAISE; 
  22.             _CATCH_END 
  23.         } 
  24.     if (!copied) 
  25.         setstate(failbit); 
  26.     osfx(); 
  27.     _CATCH_IO_END 
  28.     return (*this); 
  29.     }
  30.  
  31.